﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;

namespace AtfutureCodeMachine
{
    class Resource
    {
        /// <summary>
        /// 得到page页面内容
        /// </summary>
        /// <param name="pageName"></param>
        /// <returns></returns>
        public static string GetPage(string pageName)
        {
            try
            {
                Assembly _assembly;
                StreamReader _textStreamReader;

                _assembly = Assembly.GetExecutingAssembly();
                _textStreamReader = new StreamReader(_assembly.GetManifestResourceStream("AtfutureCodeMachine.Web." + pageName), Encoding.GetEncoding("gb2312"));

                if (_textStreamReader.Peek() != -1)
                {
                    return _textStreamReader.ReadToEnd();
                }
            }
            catch { }

            return "";
        }

        /// <summary>
        /// 得到图片流
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static Stream GetStream(string image)
        {
            try
            {
                Assembly _assembly;
                StreamReader _textStreamReader;

                _assembly = Assembly.GetExecutingAssembly();
                _textStreamReader = new StreamReader(_assembly.GetManifestResourceStream("AtfutureCodeMachine.Web.IMG." + image)); 

                return _textStreamReader.BaseStream;
            }
            catch { }

            return null;
        }
    }
}
